/*
 * Copyright (C) 2003, Velocityme Partnership
 * RoleBean.java
 *
 * Created on 21 April 2003, 05:30
 */

package com.velocityme.entity;

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import java.util.*;
import com.velocityme.interfaces.*;
import com.velocityme.valueobjects.RoleValue;
import com.velocityme.interfaces.ServiceUnavailableException;
import com.velocityme.valueobjects.PermissionValueToString;

/**
 *
 * @author  Robert Crida Work
 * @ejb.bean
 *           type="CMP"
 *           cmp-version="2.x"
 *           name="Role"
 *           jndi-name="ejb/Role"
 *           view-type="local"
 * @ejb.transaction type="Required"
 *
 * @ejb.value-object match="*"
 *
 * @ejb.persistence table-name="role"
 *
 * @ejb.util generate="physical"
 *
 * @ejb.finder signature="java.util.Collection findAll()"
 *              query="SELECT OBJECT(o) FROM Role o WHERE o.nodeLocal.dBObjectLocal.isDeleted = FALSE"
 *
 * @jboss.persistence create-table="true"
 *                    remove-table="false"
 */
public abstract class RoleBean implements EntityBean {
    
    /**
    * Context set by container
    */
    private javax.ejb.EntityContext m_entityContext;

    public void setEntityContext(javax.ejb.EntityContext entityContext) {
        m_entityContext = entityContext;
    }

    public void unsetEntityContext() {
        m_entityContext = null;
    }
  
    /** @ejb.create-method */
    public com.velocityme.interfaces.RolePK ejbCreate(com.velocityme.interfaces.NodeLocal p_nodeLocal,
                                                      com.velocityme.valueobjects.RoleValue p_value,
                                                      java.util.Set p_permissionsLocal) throws CreateException {
        setRoleId(p_nodeLocal.getNodeId());
        // EJB 2.0 spec says return null for CMP ejbCreate methods.
        return null;
    }

    public void ejbPostCreate(com.velocityme.interfaces.NodeLocal p_nodeLocal,
                              com.velocityme.valueobjects.RoleValue p_value,
                              java.util.Set p_permissionsLocal) throws CreateException {
        // CMR relations must be set in ejbPostCreate
        setRoleValue(p_value);
        setNodeLocal(p_nodeLocal);
        setPermissionsLocal(p_permissionsLocal);
    }

    /**
     *  This gets a local object from a remote object.
     *  @ejb.interface-method view-type="remote"
     */
    public com.velocityme.interfaces.RoleLocal getLocal() {
        return (RoleLocal)m_entityContext.getEJBLocalObject();
    }
    
    /** @ejb.interface-method view-type="local" */
    public abstract com.velocityme.valueobjects.RoleValue getRoleValue();
    /** @ejb.interface-method view-type="local" */
    public abstract void setRoleValue(com.velocityme.valueobjects.RoleValue p_value);
    
    //=======================================================================
    //
    //                   ATTRIBUTES
    //
    //=======================================================================
      
    /**
     * @ejb.persistence column-name="roleId"
     * @ejb.interface-method view-type="local"
     * @ejb.pk-field 
     */
    public abstract java.lang.Integer getRoleId();
    /** @ejb.interface-method view-type="local" */
    public abstract void setRoleId(java.lang.Integer roleId);

   /**
     * @ejb.persistence column-name="isRecursive"
     * @ejb.interface-method view-type="local"
     */
    public abstract java.lang.Boolean getIsRecursive();
    /** @ejb.interface-method view-type="local" */
    public abstract void setIsRecursive(java.lang.Boolean isRecursive);

    //=======================================================================
    //
    //                   RELATIONSHIPS
    //
    //=======================================================================
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Role-Node"
     *               role-name="Role-has-a-Node"
     * @jboss.relation fk-column="nodeIdFk"
     *                 related-pk-field="nodeId"
     * @ejb.value-object match="*" 
     *                   aggregate="com.velocityme.valueobjects.NodeValue"
     *                   aggregate-name="NodeValue"
     */
    public abstract com.velocityme.interfaces.NodeLocal getNodeLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setNodeLocal(com.velocityme.interfaces.NodeLocal nodeLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Role-Permission"
     *               role-name="Role-has-many-Permissions"
//     *               target-ejb="Permission"
//     *               target-role-name="Permission-has-many-Roles"
//     *               target-multiple="yes"
     * @jboss.relation fk-column="roleId"
     *                 related-pk-field="permissionId"
     * @jboss.relation-table table-name="rolepermission"
     *                       create-table="true"
     *                       remove-table="false"
     */
    public abstract java.util.Set getPermissionsLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setPermissionsLocal(java.util.Set permissions);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="UserAccess-Role"
     *               role-name="Role-may-have-many-UserAccesses"
     */
    public abstract java.util.Collection getUserAccessesLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setUserAccessesLocal(java.util.Collection userAccessesLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="GroupAccess-Role"
     *               role-name="Role-may-have-many-GroupAccesses"
     */
    public abstract java.util.Collection getGroupAccessesLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setGroupAccessesLocal(java.util.Collection groupAccessesLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Transition-Role"
     *               role-name="Role-may-be-responsible-for-many-Transitions"
     * @jboss.relation fk-column="roleId"
     *                 related-pk-field="transitionId"
     * @jboss.relation-table table-name="responsibleroles"
     *                       create-table="true"
     *                       remove-table="false"
     */
    public abstract java.util.Collection getResponsibleTransitionsLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setResponsibleTransitionsLocal(java.util.Collection transitions);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="TaskStateMachine-Role"
     *               role-name="Roles-can-be-interested-in-many-TaskStateMachines"
     * @jboss.relation fk-column="roleId"
     *                 related-pk-field="taskStateMachineId"
     * @jboss.relation-table table-name="taskstatemachineinterestedroles"
     *                       create-table="true"
     *                       remove-table="false"
     */
    public abstract java.util.Collection getInterestedTaskStateMachinesLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setInterestedTaskStateMachinesLocal(java.util.Collection taskStateMachinesLocal);
    
    //=======================================================================
    //
    //                   MANAGEMENT METHODS
    //
    //=======================================================================
    
}
